package gui;

import gui.models.OpcjeRenderer;
import gui.models.TyranizatorTableModel;

import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JPanel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Date;

import javax.swing.JTextPane;
import javax.swing.border.TitledBorder;

import utils.TyranizatorLogger;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;

public class Tyranizator {

	private JFrame frmTyranizatorSymulacja;
	private JTable table;
	private TyranizatorTableModel tableModel;
	private TyranizatorLogger logger;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Tyranizator window = new Tyranizator();
					window.frmTyranizatorSymulacja.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Tyranizator() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmTyranizatorSymulacja = new JFrame();
		frmTyranizatorSymulacja.setTitle("Tyranizator - Symulacja algorytmu elekcji metod\u0105 Tyrana");
		frmTyranizatorSymulacja.setBounds(100, 100, 727, 512);
		frmTyranizatorSymulacja.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		tableModel = new TyranizatorTableModel();
		
		JScrollPane scrollPane = new JScrollPane();
		
		table = new JTable();
		scrollPane.setViewportView(table);
		table.setModel(tableModel);
		
		JPanel panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Opcje", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JScrollPane scrollPane_1 = new JScrollPane();
		GroupLayout groupLayout = new GroupLayout(frmTyranizatorSymulacja.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(scrollPane_1, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 687, Short.MAX_VALUE)
						.addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 687, Short.MAX_VALUE)
						.addComponent(scrollPane, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 687, Short.MAX_VALUE))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 173, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 58, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(scrollPane_1, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
					.addContainerGap())
		);
		
		JTextArea textAreaKonsola = new JTextArea();
		textAreaKonsola.setEditable(false);
		scrollPane_1.setViewportView(textAreaKonsola);
		
		JLabel lblDodajProces = new JLabel("Dodaj proces nr:");
		
		JSpinner spinner = new JSpinner();
		spinner.setModel(new SpinnerNumberModel(new Integer(0), null, null, new Integer(1)));
		
		JButton btnDodajProces = new JButton("Dodaj");
		btnDodajProces.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("[Dodaj Proces]");
			}
		});
		
		JButton btnUsunProces = new JButton("Usun Proces");
		btnUsunProces.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("[Usun Proces]");
			}
		});
		
		JButton btnElekcja = new JButton("Elekcja");
		btnElekcja.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.out.println("[Elekcja]");
			}
		});
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblDodajProces)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(spinner, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnDodajProces)
					.addPreferredGap(ComponentPlacement.RELATED, 264, Short.MAX_VALUE)
					.addComponent(btnUsunProces)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnElekcja)
					.addContainerGap())
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
							.addComponent(btnElekcja)
							.addComponent(btnUsunProces))
						.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
							.addComponent(lblDodajProces)
							.addComponent(spinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addComponent(btnDodajProces)))
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		panel.setLayout(gl_panel);
		frmTyranizatorSymulacja.getContentPane().setLayout(groupLayout);
		table.getColumnModel().getColumn(0).setPreferredWidth(73);
		tableModel.addRow(new Object[]{1,true,true,"sfsd"});
		logger = new TyranizatorLogger(textAreaKonsola);
		logger.addLog("Uruchomienie programu" );
		
		
		
		
	}
}

